package main

import (
	"fmt"
)

func main() {
	//声明map 指定key类型为string和value类型为int ，需要使用make初始化，map也是引用类型
	var numbers map[string]int = make(map[string]int)
	//声明map第二种方式
	numbers2 := make(map[string]int)
	fmt.Println(numbers, numbers2)

	numbers["one"] = 1 //为map赋值
	numbers["ten"] = 10
	fmt.Printf("numbers[\"ten\"]=%d\n", numbers["ten"])
	fmt.Println(numbers)

	//直接初始化map
	rating := map[string]float32{"C": 5, "Go": 4.5, "Python": 4.5, "C++": 2}
	csharpRating, ok := rating["C#"] //通过key获取value时有两个返回值，第二个表示是否存在key
	if ok {
		fmt.Println("C# is in the map and its rating is ", csharpRating)
	} else {
		fmt.Println("We have no rating associated with C# in the map")
	}

	delete(rating, "C") //删除key

	fmt.Println(rating)
}
